/**
 * Created by LaoXu on 2017/12/20.
 * @description:工具类
 */
!(function (root, factory) {
    if (typeof define === 'function' && define.amd) {
        define([], factory);
    } else if (typeof exports === 'object') {
        module.exports = factory();
    } else {
        root.XUtil = factory();
    }

}(this, function () {
    var XUtil = {};

    /* 定义常量 */
    var protocol = 'http';
    var host = '10.9.171.42';
    var port = '8099';

    var token = 'u_token';

    createProp(XUtil, 'token', token);


    // 定义baseUrl属性，不可修改
    Object.defineProperty(XUtil, 'baseUrl', {
        value: protocol + '://' + host + ':' + port,
        enumerable: true
    });

    /**
     * 为对象创建属性及值
     * @param obj
     * @param prop
     * @param value
     */
    function createProp(obj, prop, value) {
        Object.defineProperty(obj, prop, {
            value: value,
            enumerable: true
        });
    }


    /**
     * 获取URL上的参数信息
     * @param _url
     * @param _name
     */
    XUtil.getUrlParams = function (_url) {
        var url = _url || "",
            obj = {},
            index = -1,
            param = "",
            paramArr = [];

        if (!this.isStrEmpty(_url)) {
            index = _url.indexOf('?');
            if (index !== -1) {
                param = _url.substring(_url.indexOf('?') + 1, url.length);
                paramArr = param.split("&");
                paramArr.forEach(function (item, index) {
                    var key = item.split('=');
                    obj[key[0]] = key[1];
                });
            }
        }
        return obj;
    }

    return XUtil;
}));